package com.yoomiito.app.ui.anyview.invite

import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.target.Target
import com.bumptech.glide.request.transition.Transition
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.model.bean.UserInfo
import com.yoomiito.app.model.colleage.SubjectShareInfo
import com.yoomiito.app.share.ui.BaseShareView
import com.yoomiito.app.utils.*
import kotlinx.android.synthetic.main.act_subject_detail.*
import kotlinx.coroutines.*

class ShareSubjectView(override var context: Context, val frameLayout: FrameLayout) : BaseShareView(context) {
    private val userInfo: UserInfo = UserInfoConfig.getUser()
    private lateinit var subtitleTv: TextView
    private lateinit var subjectShareInfo:SubjectShareInfo
    init {
        initView()
    }

    private fun initView() {
        val parentView = LayoutInflater.from(context).inflate(R.layout.view_invite_friend, null, false)
        parentView.findViewById<androidx.recyclerview.widget.RecyclerView>(R.id.rcy).visibility = View.GONE
        mShowADView = parentView.findViewById(R.id.ad_view)
        val lp = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
        frameLayout.addView(parentView, lp)

        mAdView = LayoutInflater.from(context).inflate(R.layout.view_share_subject, null, false)
        mAdIv = mAdView.findViewById(R.id.shareLl)
        val inviteCodeTv = mAdView.findViewById<TextView>(R.id.inviteCodeTv)
        inviteCodeTv.typeface = AllUtils.getTypeface()
        inviteCodeTv.text = userInfo.invitation_code
        val userPhoto = mAdView.findViewById<ImageView>(R.id.user_photo)
        ImageLoader.getInstance().into(context, userInfo.headimgurl, userPhoto)
        mAdView.findViewById<TextView>(R.id.user_name).text = userInfo.name
        subtitleTv = mAdView.findViewById(R.id.user_subtitle)
        mErWeiMaIv = mAdView.findViewById(R.id.erweimaIv)

    }

    override fun setData(any: Any) {
        subjectShareInfo = any as SubjectShareInfo
        subtitleTv.text = subjectShareInfo.share_txt
        makeErWeiMa(subjectShareInfo.url)
        ImageUtils.layoutView(mAdView, App.mWidthPx, App.mHeightPx)
        makeThemeAd(subjectShareInfo.share_img,0)

    }
}